<template>
  <div class="container">
    <van-nav-bar fixed border title="发布文章" left-text="取消" @click-left="$router.go(-1)" left-arrow>
      <template #right>
        <van-button icon="plus" size="small" color="#d75f95" class="xiewenzhang" @click="sharetext">发布文章</van-button>
      </template>
    </van-nav-bar>
    <div class="wenzhang">
      <van-field v-model="user.title"
                 rows="2"
                 autosize
                 label="标题"
                 type="textarea"
                 placeholder="请输入标题"
                 show-word-limit />
      <van-field v-model="user.message"
                 rows="2"
                 autosize
                 label="文章内容"
                 type="textarea"
                 maxlength="300"
                 placeholder="请输入文章内容"
                 show-word-limit />
    </div>
  </div>
</template>

<script>
export default {
  name: 'ShareText',
  data () {
    return {
      time: Date().toString().slice(3, 16),
      user: {
        aut_name: 'damo',
        title: '',
        comm_count: '0',
        pubdate: Date().toString().slice(3, 16),
        message: '',
        photoid: '3',
        textid: 300364,
        id: 40
      }
    }
  },
  methods: {
    sharetext () {
      if (this.user.title.trim().length > 0 && this.user.message.trim().length > 0) {
        this.$store.commit('addNewText', this.user)
        this.$toast.success('发布成功')
        this.$router.go(-1)
      } else {
        this.$toast.fail('请输入标题或内容')
      }
    }
  }
}
</script>

<style scoped lang="less">
  .xiewenzhang {
    border-radius: 15px;
    .van-icon

  {
    color: #fff;
  }

  }
  .wenzhang {
    margin-top: 100px;
    .van-cell:nth-child(2){
      min-height: 100px;
    .van-field__body{
      min-height:100px!important;
    }
  }
  }
</style>
